package com.helloworld;

import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.mylhyl.circledialog.CircleDialog;
import com.mylhyl.circledialog.callback.ConfigButton;
import com.mylhyl.circledialog.callback.ConfigDialog;
import com.mylhyl.circledialog.callback.ConfigInput;
import com.mylhyl.circledialog.params.ButtonParams;
import com.mylhyl.circledialog.params.DialogParams;
import com.mylhyl.circledialog.params.InputParams;
import com.mylhyl.circledialog.params.ProgressParams;
import com.mylhyl.circledialog.view.listener.OnInputClickListener;

import java.util.ArrayList;
import java.util.List;

public class DialogListActivity extends AppCompatActivity {

    private ListView mLv;
    private List<String> mList;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialog_list);
        mList=new ArrayList<>();
        mList.add("Simple");
        for (int i=0;i<20;i++){
            mList.add(""+i);
        }
        mLv= (ListView) findViewById(R.id.lv_dialog_list);
        mLv.setAdapter(new BaseAdapter() {
            @Override
            public int getCount() {
                return mList.size();
            }

            @Override
            public Object getItem(int position) {
                return mList.get(position);
            }

            @Override
            public long getItemId(int position) {
                return position;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                TextView textView=new TextView(DialogListActivity.this);
                textView.setPadding(10,10,10,10);
                textView.setText((String) getItem(position));
                return textView;
            }
        });
        mLv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position){
                    case 0://简单的对话框
                        new CircleDialog.Builder(DialogListActivity.this)
                                .setTitle("标题")
                                .setText("提示框")
                                .setPositive("确定", null)
                                .show();
                        break;
                    case 1://确定框
                        new CircleDialog.Builder(DialogListActivity.this)
                                .setCanceledOnTouchOutside(false)
                                .setCancelable(false)
                                .setTitle("标题")
                                .setText("确定框")
                                .setNegative("取消", null)
                                .setPositive("确定", new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        Toast.makeText(DialogListActivity.this, "确定", Toast.LENGTH_SHORT).show();
                                    }
                                })
                                .show();
                        break;
                    case 2://选择框
                        final String[] items = {"拍照", "从相册选择", "小视频"};
                        new CircleDialog.Builder(DialogListActivity.this)
                                .configDialog(new ConfigDialog() {
                                    @Override
                                    public void onConfig(DialogParams params) {
                                        //增加弹出动画
//                                        params.animStyle = R.style.dialogWindowAnim;
                                    }
                                })
                                .setTitle("标题")
                                .setTitleColor(Color.BLUE)
                                .setItems(items, new AdapterView.OnItemClickListener() {
                                    @Override
                                    public void onItemClick(AdapterView<?> parent, View view, int
                                            position, long id) {

                                    }
                                })
                                .setNegative("取消", null)
                                .configNegative(new ConfigButton() {
                                    @Override
                                    public void onConfig(ButtonParams params) {
                                        //取消按钮字体颜色
                                        params.textColor = Color.RED;
                                    }
                                })
                                .show();
                        break;

                    case 3://进度条
                        final DialogFragment dialogFragment = new CircleDialog.Builder(DialogListActivity.this)
                                .setProgressText("登录中...")
                                .setProgressStyle(ProgressParams.STYLE_SPINNER)
//                        .setProgressDrawable(R.drawable.bg_progress_s)
                                .show();
                        new Handler().postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                dialogFragment.dismiss();
                            }
                        }, 3000);
                        break;
                    case 4://编辑框
                        new CircleDialog.Builder(DialogListActivity.this)
                                .setCanceledOnTouchOutside(false)
                                .setCancelable(true)
                                .setTitle("输入框")
                                .setInputHint("请输入条件")
                                .configInput(new ConfigInput() {
                                    @Override
                                    public void onConfig(InputParams params) {
//                                params.inputBackgroundResourceId = R.drawable.bg_input;
                                    }
                                })
                                .setNegative("取消", null)
                                .setPositiveInput("确定", new OnInputClickListener() {
                                    @Override
                                    public void onClick(String text, View v) {
                                        Toast.makeText(DialogListActivity.this, text, Toast.LENGTH_SHORT).show();
                                    }
                                })
                                .show();
                        break;
                    default:
                        break;
                }
            }
        });
    }
}
